﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
namespace DTO
{
    public class Category
    {
        int id;
        String userID;
        String name;

        public Category()
        {
        }

        /// <summary>
        /// Category ID.
        /// </summary>
        public int ID
        {
            get { return this.id; }
        }
          /// <summary>
        /// Create DTO.Category instance using SqlDataReader object.
        /// </summary>
        /// <param name="reader">Object contains informations get from DB.</param>
        public Category(SqlDataReader reader)
        {
            if (reader != null && !reader.IsClosed)
            {
                 id = reader.GetInt32(0);
                 userID = reader.GetString(1);
                 name = reader.GetString(2);
             }
        }

        /// <summary>
        /// ID of the user who own this category.
        /// </summary>
        public String UserID
        {
            get { return this.userID; }
            set 
            {
                if (value == null || "".Equals(value))
                    throw new Exception("The UserID is null.");
                else
                    this.userID = value;
            }
        }

        /// <summary>
        /// Category name.
        /// </summary>
        public String Name
        {
            get { return this.name; }
            set
            {
                if (value == null || "".Equals(value))
                    throw new Exception("The category name is null.");
                else
                    this.name = value;
            }
        }
    }
}